/*
	fmtunePlugin.cpp

	Copyright (c) 2009 by Lms <lms.cze7@gmail.com>

 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************
*/

#include "fmtuneSettings.h"
#include <QMessageBox>
#ifdef useBASS
#include "bass/bass.h"
#include "bassfce.h"
#endif
fmtuneSettings::fmtuneSettings(QString profileName) : m_profile_name(profileName)
{
	ui.setupUi(this);
#ifdef useBASS
	ui.labelAbout->setText(ui.labelAbout->text().arg(QString("%1 BASS").arg(getPluginVersion())));
#else
	ui.labelAbout->setText(ui.labelAbout->text().arg(QString("%1 Phonon").arg(getPluginVersion())));
#endif

	ui.listWidgetOutputDevice->addItem( tr("<default>") );

#ifdef useBASS
	BASS_DEVICEINFO i;
	int c;
	for (c=1;BASS_GetDeviceInfo(c,&i);c++) { // device 1 = 1st real device
//		if (i.flags&BASS_DEVICE_ENABLED) { // enabled, so add it...
			ui.listWidgetOutputDevice->addItem( /*QLatin1String(*/i.name/*)*/ );
//		}
	}
#endif

	//QSettings settings(QSettings::defaultFormat(),QSettings::SystemScope, SystemsCity::PluginSystem()->getProfilePath(), "fmtune");
	QSettings settings(QSettings::defaultFormat(),QSettings::UserScope, "qutim/qutim."+m_profile_name, "fmtune");
	ui.listWidgetOutputDevice->setCurrentRow(settings.value("devices/current", "0").toInt());
	qDebug()<<"Current device" << settings.value("devices/current", "0").toInt();

	#ifdef __linux__
		ui.checkBoxDMIX->setVisible(true);
		if (settings.value("devices/dmix", "0").toInt()==1){
			ui.checkBoxDMIX->setCheckState(Qt::Checked);
		}
		else {
			ui.checkBoxDMIX->setCheckState(Qt::Unchecked);
		}
	#else
		ui.checkBoxDMIX->setVisible(false);
	#endif

#ifdef useBASS
	//Plugins
	for (int i = 0; i < BASSGetPluginsCount(); i++) {
		ui.listPlugins->addItem(BASSGetPluginName(i));
	}
#endif

	if (settings.value("shortcuts/enabled", "0").toInt()==1){
		ui.checkBoxActivateGlobalShortcuts->setCheckState(Qt::Checked);
	}
	else {
		ui.checkBoxActivateGlobalShortcuts->setCheckState(Qt::Unchecked);
	}


	ui.lineEditRadioOnOff->setText("Ctrl+Alt+F");
	ui.lineEditRadioOnOff->setDisabled(true);

	ui.lineEditVolumeUp->setVisible(false);
	ui.lineEditVolumeDown->setVisible(false);
	ui.lineEditVolumeMute->setVisible(false);

	ui.labelVolumeUp->setVisible(false);
	ui.labelVolumeDown->setVisible(false);
	ui.labelVolumeMute->setVisible(false);
}

fmtuneSettings::~fmtuneSettings()
{

}

void fmtuneSettings::saveSettings()
{
	//QSettings settings(QSettings::defaultFormat(),QSettings::SystemScope, SystemsCity::PluginSystem()->getProfilePath(), "fmtune");
	QSettings settings(QSettings::defaultFormat(),QSettings::UserScope, "qutim/qutim."+m_profile_name, "fmtune");
	settings.setValue("devices/current", ui.listWidgetOutputDevice->currentRow());

	#ifdef __linux__
		if (ui.checkBoxDMIX->checkState()==2){
			settings.setValue("devices/dmix", "1");
		}
		else {
			settings.setValue("devices/dmix", "0");
		}
	#endif

	if (ui.checkBoxActivateGlobalShortcuts->checkState()==2){
		settings.setValue("shortcuts/enabled", "1");
	}
	else {
		settings.setValue("shortcuts/enabled", "0");
	}
}
